﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <link href="../../../lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
    <script src="../../../lib/jquery/jquery-1.3.2.min.js" type="text/javascript"></script>
    <script src="../../../lib/ligerUI/js/core/base.js" type="text/javascript"></script>
    <script src="../../../lib/ligerUI/js/plugins/ligerGrid.js" type="text/javascript"></script> 
     <script src="../CustomersData.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            window['g'] = 
            $("#maingrid4").ligerGrid({
                checkbox: true,
                columns: [
                { display: '主键', name: 'CustomerID', align: 'left', width: 140 },
                { display: '公司名', name: 'CompanyName', minWidth: 60, width: 140 },
                { display: '联系名', name: 'ContactName', width: 120,align:'left' },
                { display: '城市', name: 'City', width: 140 }
                ], dataAction: 'server',pageSize:10,
                data: CustomersData,
                width: '100%', height: '100%', isChecked: f_isChecked, onCheckRow: f_onCheckRow, onCheckAllRow: f_onCheckAllRow
            });
            

            $("#pageloading").hide();
        });
        function f_onCheckAllRow(checked)
        {
            for (var rowid in this.records)
            {
                if(checked)
                    addCheckedCustomer(this.records[rowid]['CustomerID']);
                else
                    removeCheckedCustomer(this.records[rowid]['CustomerID']);
            }
        }

        /*
        该例子实现 表单分页多选
        即利用onCheckRow将选中的行记忆下来，并利用isChecked将记忆下来的行初始化选中
        */
        var checkedCustomer = [];
        function findCheckedCustomer(CustomerID)
        {
            for(var i =0;i<checkedCustomer.length;i++)
            {
                if(checkedCustomer[i] == CustomerID) return i;
            }
            return -1;
        }
        function addCheckedCustomer(CustomerID)
        {
            if(findCheckedCustomer(CustomerID) == -1)
                checkedCustomer.push(CustomerID);
        }
        function removeCheckedCustomer(CustomerID)
        {
            var i = findCheckedCustomer(CustomerID);
            if(i==-1) return;
            checkedCustomer.splice(i,1);
        }
        function f_isChecked(rowdata)
        {
            if (findCheckedCustomer(rowdata.CustomerID) == -1)
                return false;
            return true;
        }
        function f_onCheckRow(checked, data)
        {
            if (checked) addCheckedCustomer(data.CustomerID);
            else removeCheckedCustomer(data.CustomerID);
        }
        function f_getChecked()
        {
            alert(checkedCustomer.join(','));
        }
    </script>
</head>
<body style="padding:6px; overflow:hidden;">
<div class="l-loading" style="display:block" id="pageloading"></div> 
  <form>
  <div>
  获取选中的行： <input type="button" value="获取" onclick="f_getChecked()" />
  </div>
    <div id="maingrid4" style="margin:0; padding:0"></div>
  </form>


  <div style="display:none;">
  <!-- g data total ttt -->
</div>
 
</body>
</html>
